<?php

/**
 * XHTML_I18n_Element, xhtml_lib
 * 
 * This file contains the source code for the XHTML_I18n_Element class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_I18n_Attributes.php";
include_once "Echoable.php";

/**
 * The XHTML_I18n_Element abstract class implements the internationalization 
 * atributes and methods for some of the xhtml elements as a part of a 
 * xhtml-strict php-handler implementation.
 */
abstract class XHTML_I18n_Element implements XHTML_I18n_Attributes , Echoable {

    /**
     * Language code, as per [RFC3066], for the lang xhtml-i18n-attribute.
     *
     * @var string
     */
    protected $lang;
    
    /**
     * Language code, as per [RFC3066], for the xml:lang xhtml-i18n-attribute.
     *
     * @var string
     */
    protected $xmlLang;
    
    /**
     * Text direction (ltr | rtl) for the dir xhtml-i18n-attribute.
     *
     * @var string
     */
    protected $dir;
    
    
    // Method implementation for the XHTML_I18n_Attributes interface.
    
    /**
     * Sets the language code for this element, as per [RFC3066].
     *
     * @param string $languageCode
     */
    function setLang($languageCode)
    {
        $this->lang = $languageCode;
    }
    
    /**
     * Gets the language code, as per [RFC3066], that has been set for this element
     *
     * @return string
     */
    function getLang()
    {
        return $this->lang;
    }
    
    /**
     * Sets the xml language code for this element, as per [RFC3066].
     *
     * @param string $languageCode
     */
    function setXMLLang($languageCode)
    {
        $this->xmlLang = $languageCode;
    }
    
    /**
     * Gets the xml language code, as per [RFC3066], that has been set for this element
     *
     * @return string
     */
    function getXMLLang()
    {
        return $this->xmlLang;
    }
    
    /**
     * Sets the text direction for this element.
     * Valid values: ltr, rtl.
     *
     * @param string $dir
     */
    function setDir($dir)
    {
        $this->dir = $dir;
    }
    
    /**
     * Gets the text direction that has been set for this element.
     * Values: ltr, rtl.
     *
     * @return string
     */
    function getDir()
    {
        return $this->dir;
    }
    
    
    // Method implementation for the Echoable interface.
    
    /**
     * Returns the string representation for echoing the class atributes.
     *
     * @return string
     */
    function toString()
    {
        $auxString = " ";
        
        // An attribute is added to the return string only if it is set.
        
        if (isset($this->lang)) {
            $auxString = $auxString."lang=\"".$this->lang."\" ";
        }
        
        if (isset($this->xmlLang)) {
            $auxString = $auxString."xml:lang=\"".$this->xmlLang."\" ";
        }
        
        if (isset($this->dir)) {
            $auxString = $auxString."dir=\"".$this->dir."\" ";
        }
        
        return $auxString;
        
    }
    
}
?>